const {BrowserWindow , Menu} = require('electron');

var winAbout;

var template = [
    {
      label: '文件',
      submenu: [
        {
          label: '重新加载',
          click: function(item, focusedWindow) {
            if (focusedWindow)
              focusedWindow.reload();
          }
          
        },
        {
          label: '退出',
          accelerator: 'CmdOrCtrl+W',
          role: 'close',
        },
      ]
    },
    {
      label: '窗口',
      role: 'window',
      submenu: [
        {
          label: '最小化',
          accelerator: 'CmdOrCtrl+M',
          role: 'minimize'
        },
        {
          label: '关闭',
          accelerator: 'CmdOrCtrl+W',
          role: 'close'
        },
      ]
    },
    {
      label: '帮助',
      role: 'help',
      submenu: [
        {
            label:"关于",
            click:function about() {
                var winAbout = new BrowserWindow({
                    width: 200,
                    height: 150,
                    fullscreen:false,
                    minimizable:false,
                    maximizable:false,
                    fullscreenable:false,
                    webPreferences: {
                      nodeIntegration: true,
                      enableRemoteModule:true
                    }
                });
                
                winAbout.on('closed', function() {
                    win1 = null;
                    console.log("关闭子窗口");
                });
                winAbout.setMenu(null);
                winAbout.loadFile("./html/about.html");
                
            }
        }
        // {
        //   label: '不，你不需要帮助',
        //   icon: nativeImage.createFromPath('./asset/WX20210131-145958.png')
        //   // click: function() { require('electron').shell.openExternal('http://electron.atom.io') }
        // },
        // {
        //   label:"我拒绝帮助你",
        //   icon: nativeImage.createFromPath('./asset/WX20210131-150457.png')
        // }
      ]
    },
  ];
  
  if (process.platform == 'darwin') {
    var name = require('electron').app.getName();
    template.unshift({
      label: name,
      submenu: [
        {
          label: 'About ' + name,
          role: 'about'
        },
        {
          type: 'separator'
        },
        {
          label: 'Services',
          role: 'services',
          submenu: []
        },
        {
          type: 'separator'
        },
        {
          label: 'Hide ' + name,
          accelerator: 'Command+H',
          role: 'hide'
        },
        {
          label: 'Hide Others',
          accelerator: 'Command+Alt+H',
          role: 'hideothers'
        },
        {
          label: 'Show All',
          role: 'unhide'
        },
        {
          type: 'separator'
        },
        {
          label: 'Quit',
          accelerator: 'Command+Q',
          click: function() { app.quit(); }
        },
      ]
    });
  };
  
  template.push({
    label: 'View',
    submenu: [
      {
        label: 'Reload',
        accelerator: 'CmdOrCtrl+R',
        click: function(item, focusedWindow) {
          if (focusedWindow)
            focusedWindow.reload();
        }
      },
      {
        label: 'Toggle Full Screen',
        accelerator: (function() {
          if (process.platform == 'darwin')
            return 'Ctrl+Command+F';
          else
            return 'F11';
        })(),
        click: function(item, focusedWindow) {
          if (focusedWindow)
            focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
        }
      },
      {
        label: 'Toggle Developer Tools',
        accelerator: (function() {
          if (process.platform == 'darwin')
            return 'Alt+Command+I';
          else
            return 'Ctrl+Shift+I';
        })(),
        click: function(item, focusedWindow) {
          if (focusedWindow)
            focusedWindow.toggleDevTools();
        }
      },
    ]
  });
  
  var menu = Menu.buildFromTemplate(template);
  Menu.setApplicationMenu(menu);
